expr <- read.csv("D:/杨熊冰/R语言/实验报告/mRNA_exprSet.csv",row.names = 1) #读取csv文件，将第一列作为行名
group <- substring(colnames(expr),14,15)#提取分组信息
group <- factor(group,labels = c("tumor","normal")) #分组信息改成tumor和normal,并变成因子型
if (!require("BiocManager", quietly = TRUE))
  install.packages("BiocManager")
if (!require("DESeq2", quietly = TRUE))
  BiocManager::install("DESeq2")
library(DESeq2)
coldata <- data.frame(row.names = colnames(expr), group) #建立meta信息
dds <- DESeqDataSetFromMatrix(countData = expr,
                              colData = coldata,
                              design = ~group)
dds$group<- relevel(dds$group, ref = "normal") # 指定normal作为对照组
dds2 <- DESeq(dds)
res <- results(dds2)
summary(res)
write.table(res, file= "DESeq2结果.txt")
